<template>
  <div class="projects-page">
    <div class="search-container">
      <h2 class="section-title">我的项目</h2>
      <div class="search-box">
        <i class="fas fa-search"></i>
        <input 
          type="text" 
          v-model="searchQuery" 
          placeholder="搜索项目标题..." 
          @input="handleSearch"
        >
      </div>
    </div>
    <div class="projects-container">
      <div class="project-card" v-for="project in filteredProjects" :key="project.id">
        <div class="project-image" :style="{ background: project.color }">
          <i :class="project.icon"></i>
        </div>
        <div class="project-content">
          <h3 class="project-title">{{ project.title }}</h3>
          <p class="project-description">{{ project.description }}</p>
          <div class="project-tech">
            <span v-for="(tech, index) in project.technologies" 
                  :key="index" 
                  class="tech-tag">
              {{ tech }}
            </span>
          </div>
          <div class="project-links">
            <a :href="project.demo" target="_blank" class="project-link">
              <i class="fas fa-external-link-alt"></i> 在线演示
            </a>
            <a :href="project.github" target="_blank" class="project-link">
              <i class="fab fa-github"></i> 源代码
            </a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Projects',
  data() {
    return {
      searchQuery: '',
      filteredProjects: [],
      projects: [
        {
          id: 1,
          title: '星辰博客系统',
          description: '基于 Vue.js 开发的现代化个人博客系统，支持响应式设计，提供优雅的用户体验。',
          technologies: ['Vue.js', 'CSS3', 'JavaScript'],
          icon: 'fas fa-blog',
          color: 'linear-gradient(45deg, #6366f1, #818cf8)',
          demo: '#',
          github: '#'
        },
        {
          id: 2,
          title: '智能待办清单',
          description: '一个功能丰富的待办事项管理应用，支持任务分类、优先级设置和进度追踪。',
          technologies: ['Vue.js', 'Vuex', 'Firebase'],
          icon: 'fas fa-tasks',
          color: 'linear-gradient(45deg, #f472b6, #f9a8d4)',
          demo: '#',
          github: '#'
        },
        {
          id: 3,
          title: '在线代码编辑器',
          description: '支持多种编程语言的在线代码编辑器，提供实时预览和代码高亮功能。',
          technologies: ['Vue.js', 'Monaco Editor', 'WebSocket'],
          icon: 'fas fa-code',
          color: 'linear-gradient(45deg, #93c5fd, #60a5fa)',
          demo: '#',
          github: '#'
        }
      ]
    }
  },
  watch: {
    projects: {
      immediate: true,
      handler(newProjects) {
        this.filteredProjects = [...newProjects]
      }
    }
  },
  methods: {
    handleSearch() {
      if (!this.searchQuery.trim()) {
        this.filteredProjects = [...this.projects]
        return
      }
      const query = this.searchQuery.toLowerCase().trim()
      this.filteredProjects = this.projects.filter(project => 
        project.title.toLowerCase().includes(query)
      )
    }
  }
}
</script>

<style scoped>
.projects-page {
  padding: 20px 0;
}

.section-title {
  font-size: 2rem;
  margin-bottom: 30px;
  position: relative;
  padding-bottom: 15px;
  color: var(--dark);
  padding-left: 15px;
}

.section-title:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 15px;
  width: 60px;
  height: 4px;
  background: var(--primary);
  border-radius: 2px;
}

.projects-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 30px;
  padding: 0 15px;
}

.project-card {
  background: var(--card-bg);
  border-radius: 24px;
  overflow: hidden;
  transition: var(--transition);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  width: 100%;
}

.project-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

.project-image {
  width: 100%;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: white;
}

.project-content {
  padding: 20px;
}

.project-title {
  font-size: 1.4rem;
  margin-bottom: 12px;
  color: var(--dark);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.project-description {
  color: var(--gray);
  margin-bottom: 20px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-tech {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.tech-tag {
  background: var(--primary-light);
  color: white;
  padding: 4px 12px;
  border-radius: 50px;
  font-size: 0.8rem;
}

.project-links {
  display: flex;
  gap: 12px;
}

.project-link {
  flex: 1;
  text-align: center;
  padding: 8px 16px;
  border-radius: 50px;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: var(--transition);
}

.demo-link {
  background: var(--primary);
  color: white;
}

.demo-link:hover {
  background: var(--primary-light);
}

.github-link {
  background: var(--dark);
  color: white;
}

.github-link:hover {
  background: #334155;
}

@media (max-width: 900px) {
  .projects-container {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    padding: 0 10px;
  }

  .section-title {
    font-size: 1.8rem;
    padding-left: 10px;
  }

  .section-title:after {
    left: 10px;
  }

  .project-card {
    margin-bottom: 0;
  }

  .project-image {
    height: 160px;
    font-size: 2.5rem;
  }

  .project-content {
    padding: 15px;
  }

  .project-title {
    font-size: 1.2rem;
  }

  .project-description {
    font-size: 0.9rem;
    -webkit-line-clamp: 2;
  }

  .tech-tag {
    padding: 3px 10px;
    font-size: 0.75rem;
  }

  .project-link {
    padding: 6px 12px;
    font-size: 0.85rem;
  }
}

@media (max-width: 600px) {
  .projects-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 5px;
  }

  .section-title {
    font-size: 1.5rem;
    margin-bottom: 15px;
    padding-left: 5px;
  }

  .section-title:after {
    left: 5px;
    width: 40px;
  }

  .project-card {
    margin-bottom: 0;
    border-radius: 12px;
  }

  .project-image {
    height: 120px;
    font-size: 2rem;
  }

  .project-content {
    padding: 8px;
  }

  .project-title {
    font-size: 0.85rem;
    margin-bottom: 6px;
    line-height: 1.3;
  }

  .project-description {
    font-size: 0.7rem;
    margin-bottom: 10px;
    line-height: 1.4;
  }

  .project-tech {
    gap: 4px;
    margin-bottom: 10px;
  }

  .tech-tag {
    padding: 2px 6px;
    font-size: 0.6rem;
  }

  .project-links {
    gap: 6px;
  }

  .project-link {
    padding: 4px 8px;
    font-size: 0.7rem;
    border-radius: 25px;
  }
}

.search-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 0 15px;
  flex-wrap: wrap;
  gap: 15px;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 300px;
}

.search-box i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray);
}

.search-box input {
  width: 100%;
  padding: 10px 12px 10px 35px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50px;
  font-size: 0.9rem;
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  transition: var(--transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

@media (max-width: 900px) {
  .search-container {
    padding: 0 10px;
    gap: 10px;
  }

  .search-box {
    max-width: 250px;
  }

  .search-box input {
    padding: 8px 12px 8px 32px;
    font-size: 0.85rem;
  }
}

@media (max-width: 600px) {
  .search-container {
    padding: 0 2px;
    gap: 8px;
    margin-bottom: 15px;
  }

  .search-box {
    max-width: 100%;
  }

  .search-box input {
    padding: 6px 10px 6px 30px;
    font-size: 0.8rem;
  }
}
</style> 